//
//  ViewController.m
//  STTextViewDemo
//
//  Created by yls on 14/12/11.
//  Copyright (c) 2014年 yls. All rights reserved.
//

#import "ViewController.h"
#import "STTextView.h"

#define MAXLENGTH 100

@interface ViewController ()
{
    STTextView *_textView;
    UILabel *_countLabel;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    STTextView *textView = [[STTextView alloc] initWithFrame:CGRectMake(20, 84, self.view.bounds.size.width - 40, 120)];
    textView.placeholder = [NSString stringWithFormat:@"写点什么吧，最多%@个字", @(MAXLENGTH)];
    textView.maxLength = MAXLENGTH;
    textView.font = [UIFont systemFontOfSize:15];
    [textView setTextDidChangeBlock:^(UITextView *textView) {
        _countLabel.text = [NSString stringWithFormat:@"还可以写%@个字", @(MAXLENGTH - textView.text.length)];
    }];
    
    textView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    textView.layer.borderWidth = 1.0;
    textView.layer.opacity = .7;
    
    [self.view addSubview:textView];
    _textView = textView;
    
    UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMinY(textView.frame) - 21, self.view.bounds.size.width - 40, 21)];
    countLabel.text = [NSString stringWithFormat:@"还可以写%@个字", @(MAXLENGTH)];
    [self.view addSubview:countLabel];
    _countLabel = countLabel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
